package com.example.listener;

import com.example.config.RabbitMQConfig;
import com.example.model.Event;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AnalyticsEventListener {
    
    @RabbitListener(queues = RabbitMQConfig.ANALYTICS_QUEUE)
    public void handleAnalyticsEvent(Event event) {
        log.info("Received event for analytics: {}", event);
        
        // 这里是事件转发后的处理逻辑
        // 所有发布到主交换机的事件都会被转发到analytics队列，用于数据分析
        log.info("Processing event for analytics, eventId: {}, eventType: {}, timestamp: {}", 
                event.getEventId(), event.getEventType(), event.getTimestamp());
        
        // 例如，这里可以将事件数据保存到数据库或发送到分析系统
        storeEventForAnalysis(event);
    }
    
    private void storeEventForAnalysis(Event event) {
        // 实际的数据存储逻辑
        log.info("Storing event for analysis: {}", event);
        
        // 可以根据不同的事件类型执行不同的分析处理
        switch(event.getEventType()) {
            case "USER_EVENT":
                log.info("Analyzing user behavior");
                break;
            case "ORDER_EVENT":
                log.info("Analyzing order data");
                break;
            case "NOTIFICATION_EVENT":
                log.info("Analyzing notification effectiveness");
                break;
            default:
                log.info("Analyzing generic event");
        }
    }
} 